package com.usian.controller;


import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemDesc;
import com.usian.service.ItemService;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/service/item")
public class ItemServiceController {
    @Autowired
    private ItemService itemService;

    //查询商品并分页
    @RequestMapping("/selectTbItemAllByPage")
    PageResult selectTbItemAllByPage(@RequestParam int page, @RequestParam int rows) {
        return itemService.selectTbItemAllByPage(page, rows);
    }

    //添加商品
    @RequestMapping("/insertTbItem")
    Integer insertTbItem(@RequestBody TbItem tbItem, @RequestParam String desc, @RequestParam String itemParams) {
        return itemService.insertTbItem(tbItem, desc, itemParams);
    }

    /**
     * 根据商品 ID 查询商品，商品分类，商品描述，商品规格参数
     *
     * @param itemId
     * @return
     */
    @RequestMapping("/preUpdateItem")
    Map<String, Object> preUpdateItem(@RequestParam("itemId") Long itemId) {
        return itemService.preUpdateItem(itemId);
    }

    //修改商品
    @RequestMapping("/updateTbItem")
    Integer updateTbItem(@RequestBody TbItem tbItem, @RequestParam String desc, @RequestParam String itemParams) {
        return itemService.updateTbItem(tbItem, desc, itemParams);
    }

    //删除商品
    @RequestMapping("/deleteItemById")
    Integer deleteItemById(@RequestParam Integer itemId) {
        return itemService.deleteItemById(itemId);
    }

    //查询商品基本信息
    @RequestMapping("/selectItemInfo")
    TbItem selectItemInfo(@RequestParam Long itemId) {
        return itemService.selectItemInfo(itemId);
    }

    //查询商品介绍
    @RequestMapping("/selectItemDescByItemId")
    TbItemDesc selectItemDescByItemId(@RequestParam Long itemId) {
        return itemService.selectItemDescByItemId(itemId);
    }
}